#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>

using namespace std;

int main(int argc, char *argv[])
{
    try
    {
        if (argc < 6) throw string("bad arguments\n");

        FILE *f_query[5];
        f_query[0] = fopen(argv[1], "r");
        for (int i = 1; i <= 4; ++ i) f_query[i] = fopen(argv[1 + i], "w");

        char buf[BUFSIZ], tmp[BUFSIZ];
        while (fgets(buf, BUFSIZ, f_query[0]) != 0)
        {
            int type = buf[5] - '0';
            if (type == 1) 
            {
                int p1, p2, x;
                sscanf(buf + 7, "%d, %d, %d", &p1, &p2, &x);
                fprintf(f_query[1], "%d %d %d\n", p1, p2, x);
            } 
            else if (type == 2) 
            {
                int k;
                sscanf(buf + 7, "%d, %s", &k, tmp);
                tmp[strlen(tmp) - 1] = '\0';
                fprintf(f_query[2], "%d %s\n", k, tmp);
            } 
            else if (type == 3) 
            {
                int k, h;
                sscanf(buf + 7, "%d, %d, %s", &k, &h, tmp);
                tmp[strlen(tmp) - 1] = '\0';
                fprintf(f_query[3], "%d %d %s\n", k, h, tmp);
            } 
            else if (type == 4) 
            {
                int k;
                sscanf(buf + 7, "%d, %s", &k, tmp);
                tmp[strlen(tmp) - 1] = '\0';
                fprintf(f_query[4], "%d %s\n", k, tmp);
            } else {
                throw string("bad query ") + string(buf);
            }
        }
    }
    catch (const string &err)
    {
        fprintf(stderr, "%s", err.c_str());
    }
    catch (...)
    {
        fprintf(stderr, "uncaught error\n");
    }

    return 0;
}
